<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>react_9_对props简写</title>
</head>
<body>
    <div id="test1"></div>
    <div id="test2"></div>
    <div id="test3"></div>
    <div id="test4"></div>

    <!-- 引入react 核心库 -->
    <script type="text/javascript" src="./js/react.development.js"></script>
    <!-- 引入react-dom 用于支持react操作dom -->
    <script type="text/javascript" src="./js/react-dom.development.js"></script>
    <!-- 引入babel 用于讲jsx转成js -->
    <script type="text/javascript" src="./js/babel.min.js"></script>
    <!-- 注意：从8开始需要引入一个新的js文件了，目的是对props加上限制 -->
    <script type="text/javascript" src="./js/prop-types.js"></script>

    <!-- 组 件 -->
    <script type="text/babel">
        class Person extends React.Component{
            //聊一下构造器，构造器中传不传props取决你你在不在构造器中使用this.props！！！！！
            //如果super(props) 那么this.props 将会undefined！！！！！！！！！！ 面试


            //对标签属性进行类型限制 简写，放在里面，目的是给Persion这个类上加一个属性，加上关键字static
            static propTypes={
                name: PropTypes.string.isRequired,
                gender: PropTypes.string,
                age: PropTypes.number
            }
            //进行默认值
            static defaultProps={
                gender:'未知',
                age:18
            }

            state = {}

            render() {
                const {name,age,gender} = this.props
                return (
                    <div>
                        <ul>
                            <li>姓名：{name}</li>
                            <li>年龄：{age+1}</li>
                            <li>性别：{gender}</li>
                        </ul>
                    </div>
                );
            }
        }
        ReactDOM.render(<Person name={"张三"} gender={"男"}/>,document.getElementById('test1'))
        ReactDOM.render(<Person name={"张三"} age={19} gender={"男"}/>,document.getElementById('test2'))
        ReactDOM.render(<Person name={"张三"} age={19} gender={"男"}/>,document.getElementById('test3'))
        const p = {name:'小棋',age: 18,gender: '女'}
        ReactDOM.render(<Person {...p}/>,document.getElementById('test4'))
    </script>
</body>

</html>